﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Domain
{
	using Falcon.Core.Domain.Enums;

	public class SpecificationBase : ISpecification
	{
		/// <summary>
		/// Gets or sets the page.
		/// </summary>
		/// <value>The page.</value>
		public int? Page
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets the page or default.
		/// </summary>
		/// <value>The page or default.</value>
		public int PageOrDefault
		{
			get
			{
				return this.Page.HasValue ? this.Page.Value : 1;
			}
		}

		/// <summary>
		/// Gets or sets the limit.
		/// </summary>
		/// <value>The limit.</value>
		public int Limit
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the limit or default.
		/// </summary>
		/// <value>The limit or default.</value>
		public int LimitOrDefault
		{
			get
			{
				return this.Limit > 0 ? this.Limit : int.MaxValue;
			}
		}

		/// <summary>
		/// Gets the start.
		/// </summary>
		/// <value>The start.</value>
		public int Start
		{
			get
			{
				return (this.PageOrDefault * this.LimitOrDefault) - this.LimitOrDefault;
			}
		}

		/// <summary>
		/// Gets the end.
		/// </summary>
		/// <value>The end.</value>
		public int End
		{
			get
			{
				return (this.Start + this.LimitOrDefault) - 1;
			}
		}

		/// <summary>
		/// Gets or sets the order.
		/// </summary>
		/// <value>The order.</value>
		public SortOrder Order
		{
			get;
			set;
		}
	}
}